﻿
using System;
using System.Drawing; 
using System.Collections.Generic; 
using MonoTouch.Foundation;
using MonoTouch.UIKit;
 
namespace Beauty.Module.Pos
{
	public partial class SelectServicesVCtrl : UIViewController
	{
		UITableView table;
		public SelectServicesVCtrl () : base ("SelectServicesVCtrl", null)
		{
		}

		public override void DidReceiveMemoryWarning ()
		{
			// Releases the view if it doesn't have a superview.
			base.DidReceiveMemoryWarning ();
			
			// Release any cached data, images, etc that aren't in use.
		}


		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			ivBack.Image = PosUtility.ImageFrom ("SelectCustomerVCtrl_ic_back");
			ivClose.Image = PosUtility.ImageFrom ("CreateNewJobshetVCtrl_bt_close");
			segmentCategory.Layer.CornerRadius = 50.0f;


			table = new UITableView(new RectangleF(90,112,846,486)) ; // defaults to Plain style
			//table.AutoresizingMask = UIViewAutoresizing.All;
			table.Layer.BorderWidth = 1.0f;
			table.Layer.CornerRadius = 5.0f;
			table.Layer.BorderColor = UIColorExtensions.FromHexString ("#dbdbdb").CGColor;
			//table.BackgroundColor = UIColor.FromRGB (218, 255, 127);
			table.RowHeight = 82f;
			table.SeparatorColor = UIColor.FromRGB (219, 219, 219);

			List<SelectServiceItems> tableItems = new List<SelectServiceItems>();



			tableItems.Add (new SelectServiceItems("") { SubHeading="", ImageName=""});
			tableItems.Add (new SelectServiceItems("Hair Cut") { SubHeading="$15", ImageName="SelectCustomerVCtrl_cus_img1.png"});
			tableItems.Add (new SelectServiceItems("Service 2") { SubHeading="$15", ImageName="SelectCustomerVCtrl_cus_img1.png"});
			tableItems.Add (new SelectServiceItems("Service 3") { SubHeading="$15", ImageName="SelectCustomerVCtrl_cus_img1.png"});
			tableItems.Add (new SelectServiceItems("Service 4") { SubHeading="$15", ImageName="SelectCustomerVCtrl_cus_img1.png"});
			tableItems.Add (new SelectServiceItems("Service 5") { SubHeading="$15", ImageName="SelectCustomerVCtrl_cus_img1.png"});
			table.Source = new SelectServiceSource(tableItems);
			Add (table);
			// Perform any additional setup after loading the view, typically from a nib.


	
		}
		public class SelectServiceItems {
			public string Heading { get; set; }

			public string SubHeading { get; set; }

			public string ImageName { get; set; }

			public UITableViewCellStyle CellStyle
			{
				get { return cellStyle; }
				set { cellStyle = value; }
			}
			protected UITableViewCellStyle cellStyle = UITableViewCellStyle.Default;

			public UITableViewCellAccessory CellAccessory
			{
				get { return cellAccessory; }
				set { cellAccessory = value; }
			}
			protected UITableViewCellAccessory cellAccessory = UITableViewCellAccessory.None;

			public SelectServiceItems () { }

			public SelectServiceItems (string heading)
			{ Heading = heading; }
		}

		public class SelectServiceSource : UITableViewSource {
			List<SelectServiceItems> tableItems;
			NSString cellIdentifier = new NSString("TableCell");

			public SelectServiceSource (List<SelectServiceItems> items)
			{
				tableItems = items;
			}

			/// <summary>
			/// Called by the TableView to determine how many cells to create for that particular section.
			/// </summary>
			public override int RowsInSection (UITableView tableview, int section)
			{
				return tableItems.Count;
			}

			/// <summary>
			/// Called when a row is touched
			/// </summary>
			public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
			{
				new UIAlertView("Row Selected"
					, tableItems[indexPath.Row].Heading, null, "OK", null).Show();
				tableView.DeselectRow (indexPath, true);
			}

			/// <summary>
			/// Called by the TableView to get the actual UITableViewCell to render for the particular row
			/// </summary>
			public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
			{
				// request a recycled cell to save memory
				CustomItemCell cell = tableView.DequeueReusableCell (cellIdentifier) as CustomItemCell;

				// if there are no cells to reuse, create a new one
				if (cell == null) {
					cell = new CustomItemCell (cellIdentifier);
				}

				cell.UpdateCell (tableItems[indexPath.Row].Heading
					, tableItems[indexPath.Row].SubHeading
					, UIImage.FromFile ("Module/Pos/Img/" +tableItems[indexPath.Row].ImageName) );

				return cell;
			}
		}



		public class CustomItemCell: UITableViewCell  {

			UILabel NameService, ServicePrice;
			UIImageView imageView; 
			public CustomItemCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId)
			{
				SelectionStyle = UITableViewCellSelectionStyle.Gray; 
				//ContentView.BackgroundColor = UIColor.FromRGB (218, 255, 127);

				imageView = new UIImageView();

				NameService = new UILabel () {  
					//TextAlignment =UITextAlignment.Center,
					BackgroundColor = UIColor.Clear
				};

				ServicePrice = new UILabel () { 
					//TextAlignment = UITextAlignment.Center,
					BackgroundColor = UIColor.Clear
				};

				ContentView.Add (NameService);
				ContentView.Add (ServicePrice);
				ContentView.Add (imageView);
			}

			public void UpdateCell (string caption, string subtitle, UIImage image)
			{
				imageView.Image = image;
				NameService.Text = caption;
				ServicePrice.Text = subtitle;
			}

			public override void LayoutSubviews ()
			{
				base.LayoutSubviews ();

				imageView.Frame = new RectangleF(20, 16, 46, 46);
				imageView.Layer.CornerRadius = 11.5f;
				NameService.Frame = new RectangleF(80, 30, ContentView.Bounds.Width - 63, 25);
				ServicePrice.Frame = new RectangleF(800, 30, 100, 20);
			}
		}
	}
}
